import request from '@/utils/request';

const fineBase = 'https://finereport.gw-greenenergy.com/webroot/decision/view/report';

export async function getFineReportIframe(params) {
  return request('/generation-common/finereport/getFineReportIframe', {
    method: 'POST',
    data: params,
  });
}

export async function findUserBaseInfoByToken() {
  return request('/user/user/findUserBaseInfoByToken');
}

// 拼接好地址，return 集合
export const fetchUrls = async (menuCode) => {
  const [viewletRes, oaRes] = await Promise.all([
    getFineReportIframe({ menuCode: [menuCode] }),
    findUserBaseInfoByToken(),
  ]);
  const viewletList = viewletRes?.dataFineReportBodyList || [];
  const oa = oaRes?.username || '';
  const result = viewletList.map((x) => `${fineBase}?viewlet=${x?.iframeName || ''}&oa=${oa}`);
  return Promise.resolve(result);
};
